#import "Common.h"
#import "ExplodeScore.h"

@implementation ExplodeScore

-(id) initWithPos:(CGPoint)pos score:(int)score type:(InvaderType)type
{
	if ((self = [super initWithString:@"" fontName:gFontNumber fontSize:20]))
	{
		[self autorelease];

		float destScale = 1;
		float destMove = 100;
		float time = 1;

		NSString* tmpStr = [NSString stringWithFormat:@"%d", score];
		switch(type)
		{
			case IT_Normal_1:
			case IT_Normal_2:
				destScale = 2;
				self.color = ccc3(0, 0xFF, 0xFF);
				break;
			case IT_Good:
				tmpStr = @"BONUS +1";
				destScale = 3;
				self.color = ccGREEN;
				break;
			case IT_Bad:
				tmpStr = @"BONUS CLEAR";
				destScale = 3;
				self.color = ccRED;
				break;
			case IT_Gold:
				tmpStr = [NSString stringWithFormat:@"GOLD +%d", score];
				destScale = 5;
				self.color = ccc3(255,215,0);
				break;
			default:
				break;
		}

		self.string = tmpStr;
		self.position = pos;
		[self runAction:[CCSequence actions:
						 [CCSpawn actions:
						  [CCMoveBy actionWithDuration:time position:ccp(0,destMove)],
						  [CCScaleTo actionWithDuration:time scale:destScale],
						  [CCFadeOut actionWithDuration:time], nil],
						 [CCCallFunc actionWithTarget:self selector:@selector(destroy)], nil]];
	}
	return self;
}

-(void) destroy
{
	[self stopAllActions];
	[[self parent] removeChild:self cleanup:YES];
}

@end
